package gui;

import java.awt.Font;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.LinkedList;
import java.util.concurrent.ExecutorService;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;

import board.Board;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class NPuzzle {

	public JFrame frame;
	public JButton btnRozwi;
	public JButton btnGeneruj;
	public JButton btnUstawStan;
	public JButton btnAnimuj;
	public PuzzlePanel panel;
	public JTextField textField;
	public JTextField textField_1;
	public ExecutorService exec;
	private Board puzzleBoard;
	public JButton btnZmien;
	public JTextField textField_2;
	public JButton btnZmien2;
	public JLabel lblNewLabel_3;
	private JLabel lblZnalezionoRozwizanie;
	private JLabel lblCzasRozwizywaniams;
	private JLabel lblIloIteracji;
	public JLabel lblFound;
	public JLabel lblTime;
	public JLabel lblSteps;

	/**
	 * Create the application.
	 */
	public NPuzzle() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frame = new JFrame();
		frame.setBounds(100, 100, 740, 515);
		frame.setResizable(false);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().setLayout(null);
		
		panel = new PuzzlePanel();
		panel.setBounds(10, 10, 460, 460);
		frame.getContentPane().add(panel);
		
		JLabel lblNewLabel = new JLabel("Problem N-Puzzli");
		lblNewLabel.setFont(new Font("Times New Roman", Font.BOLD, 28));
		lblNewLabel.setBounds(480, 10, 214, 38);
		frame.getContentPane().add(lblNewLabel);
		
		JPanel panel_1 = new JPanel();
		panel_1.setBounds(490, 60, 204, 377);
		frame.getContentPane().add(panel_1);
		
		JLabel lblNewLabel_1 = new JLabel("Rozmiar problemu:");
		lblNewLabel_1.setFont(new Font("Times New Roman", Font.PLAIN, 18));
		
		textField = new JTextField();
		textField.setColumns(10);
		
		btnGeneruj = new JButton("Generuj");
		btnGeneruj.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				NPuzzleProgram.buttonGeneruj();
			}
		});
		
		btnUstawStan = new JButton("Ustaw stan");
		btnUstawStan.setEnabled(false);
 btnUstawStan.addMouseListener(new MouseAdapter() {
 	@Override
 	public void mouseClicked(MouseEvent arg0) {
 		NPuzzleProgram.buttonUstawStan();
 	}
 });
		btnRozwi = new JButton("Rozwi\u0105zuj");
		btnRozwi.setEnabled(false);
		btnRozwi.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				NPuzzleProgram.buttonRozwiazuj();
			}
		});
		
		btnAnimuj = new JButton("Animuj");
		btnAnimuj.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				NPuzzleProgram.buttonAnimuj();
			}
		});
		btnAnimuj.setEnabled(false);
		btnAnimuj.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
			}
		});
		
		JLabel lblNewLabel_2 = new JLabel("Czas wy\u015Bwietlania (ms):");
		lblNewLabel_2.setFont(new Font("Times New Roman", Font.PLAIN, 18));
		
		textField_1 = new JTextField();
		textField_1.setText("500");
		textField_1.setColumns(10);
		
		btnZmien = new JButton("Zmie\u0144");
		btnZmien.setEnabled(false);
		btnZmien.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				NPuzzleProgram.buttonZmien();
			}
		});
		
		textField_2 = new JTextField();
		textField_2.setText("1");
		textField_2.setColumns(10);
		
		btnZmien2 = new JButton("Zmie\u0144");
		btnZmien2.setEnabled(false);
		btnZmien2.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				NPuzzleProgram.buttonZmien2();
			}
		});
		
		lblNewLabel_3 = new JLabel("Co ile zmian wy\u015Bwietla\u0107?");
		lblNewLabel_3.setFont(new Font("Times New Roman", Font.PLAIN, 18));
		
		lblZnalezionoRozwizanie = new JLabel("Znaleziono rozwi\u0105zanie:");
		
		lblCzasRozwizywaniams = new JLabel("Czas (ms):");
		
		lblIloIteracji = new JLabel("Ilo\u015B\u0107 krok\u00F3w:");
		
		lblFound = new JLabel("");
		lblFound.setFont(new Font("Tahoma", Font.BOLD, 11));
		
		lblTime = new JLabel("");
		lblTime.setFont(new Font("Tahoma", Font.BOLD, 11));
		
		lblSteps = new JLabel("");
		lblSteps.setFont(new Font("Tahoma", Font.BOLD, 11));
		GroupLayout gl_panel_1 = new GroupLayout(panel_1);
		gl_panel_1.setHorizontalGroup(
			gl_panel_1.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel_1.createSequentialGroup()
					.addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING, false)
						.addGroup(gl_panel_1.createSequentialGroup()
							.addComponent(btnGeneruj)
							.addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
							.addComponent(btnUstawStan))
						.addComponent(lblNewLabel_1)
						.addComponent(textField)
						.addComponent(btnRozwi, GroupLayout.DEFAULT_SIZE, 163, Short.MAX_VALUE))
					.addGap(30))
				.addGroup(gl_panel_1.createSequentialGroup()
					.addContainerGap()
					.addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_panel_1.createSequentialGroup()
							.addComponent(lblZnalezionoRozwizanie)
							.addPreferredGap(ComponentPlacement.UNRELATED)
							.addComponent(lblFound))
						.addGroup(gl_panel_1.createSequentialGroup()
							.addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING)
								.addComponent(lblIloIteracji)
								.addComponent(lblCzasRozwizywaniams))
							.addPreferredGap(ComponentPlacement.RELATED, 19, Short.MAX_VALUE)
							.addGroup(gl_panel_1.createParallelGroup(Alignment.TRAILING, false)
								.addComponent(lblSteps, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
								.addComponent(lblTime, GroupLayout.DEFAULT_SIZE, 102, Short.MAX_VALUE))))
					.addContainerGap())
				.addGroup(gl_panel_1.createSequentialGroup()
					.addGroup(gl_panel_1.createParallelGroup(Alignment.TRAILING)
						.addComponent(lblNewLabel_3)
						.addGroup(gl_panel_1.createSequentialGroup()
							.addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING)
								.addComponent(btnAnimuj, GroupLayout.DEFAULT_SIZE, 176, Short.MAX_VALUE)
								.addComponent(lblNewLabel_2, GroupLayout.DEFAULT_SIZE, 176, Short.MAX_VALUE)
								.addGroup(gl_panel_1.createSequentialGroup()
									.addGroup(gl_panel_1.createParallelGroup(Alignment.TRAILING, false)
										.addComponent(textField_2, Alignment.LEADING, 0, 0, Short.MAX_VALUE)
										.addComponent(textField_1, Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 66, GroupLayout.PREFERRED_SIZE))
									.addPreferredGap(ComponentPlacement.RELATED)
									.addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING)
										.addComponent(btnZmien2, GroupLayout.DEFAULT_SIZE, 104, Short.MAX_VALUE)
										.addComponent(btnZmien, GroupLayout.DEFAULT_SIZE, 104, Short.MAX_VALUE))))
							.addGap(8)))
					.addGap(20))
		);
		gl_panel_1.setVerticalGroup(
			gl_panel_1.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel_1.createSequentialGroup()
					.addComponent(lblNewLabel_1)
					.addGap(9)
					.addComponent(textField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(gl_panel_1.createParallelGroup(Alignment.BASELINE)
						.addComponent(btnGeneruj)
						.addComponent(btnUstawStan))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(btnRozwi)
					.addGap(18)
					.addGroup(gl_panel_1.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblZnalezionoRozwizanie)
						.addComponent(lblFound))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(gl_panel_1.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblCzasRozwizywaniams)
						.addComponent(lblTime))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(gl_panel_1.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblIloIteracji)
						.addComponent(lblSteps))
					.addGap(18)
					.addComponent(lblNewLabel_2)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(gl_panel_1.createParallelGroup(Alignment.BASELINE)
						.addComponent(textField_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(btnZmien))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(lblNewLabel_3)
					.addGap(11)
					.addGroup(gl_panel_1.createParallelGroup(Alignment.BASELINE)
						.addComponent(textField_2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(btnZmien2))
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addComponent(btnAnimuj)
					.addContainerGap(31, Short.MAX_VALUE))
		);
		panel_1.setLayout(gl_panel_1);
		frame.setVisible(true);
	}
}
